import request from '@/utils/request'

// 获取资源列表
export function getResourceList(params) {
  return request({
    url: '/resource/list',
    method: 'get',
    params
  })
}

// 获取所有资源（管理用）
export function getAllResources(params) {
  return request({
    url: '/resource/all',
    method: 'get',
    params
  })
}

// 获取资源列表（无需token）
export function getResourceListPublic(params) {
  return request({
    url: '/resource/list',
    method: 'get',
    params,
    headers: {
      'Authorization': '' // 清空Authorization头
    }
  })
}

// 获取资源详情
export function getResourceById(id) {
  return request({
    url: `/resource/${id}`,
    method: 'get'
  })
}

// 上传资源
export function uploadResource(data) {
  return request({
    url: '/resource/upload',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 更新资源
export function updateResource(data) {
  return request({
    url: '/resource/update',
    method: 'put',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 删除资源
export function deleteResource(id) {
  return request({
    url: `/resource/${id}`,
    method: 'delete'
  })
}

// 下载资源
export function downloadResource(id) {
  return request({
    url: `/resource/download/${id}`,
    method: 'post'
  })
}

// 获取我的资源
export function getMyResources(params) {
  return request({
    url: '/resource/my',
    method: 'get',
    params
  })
}

// 搜索资源
export function searchResources(params) {
  return request({
    url: '/resource/search',
    method: 'get',
    params
  })
}

// 获取资源分类
export function getResourceCategories() {
  return request({
    url: '/resource/categories',
    method: 'get'
  })
}

// 审核资源
export function reviewResource(id, data) {
  return request({
    url: `/resource/review/${id}`,
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

// 获取待审核资源
export function getPendingResources(params) {
  return request({
    url: '/resource/pending',
    method: 'get',
    params
  })
}

// 获取下载统计
export function getDownloadStatistics(id) {
  return request({
    url: `/resource/statistics/${id}`,
    method: 'get'
  })
}

// ==================== 预约相关API ====================

// 创建预订
export function createBooking(data) {
  return request({
    url: '/resource/booking',
    method: 'post',
    data
  })
}

// 获取我的预订
export function getMyBookings(params) {
  return request({
    url: '/resource/booking/my',
    method: 'get',
    params
  })
}

// 审批预订
export function approveBooking(id, data) {
  return request({
    url: `/resource/booking/approve/${id}`,
    method: 'post',
    data
  })
}

// 拒绝预订
export function rejectBooking(id, data) {
  return request({
    url: `/resource/booking/reject/${id}`,
    method: 'post',
    data
  })
}

// 获取待审批预订
export function getPendingBookings(params) {
  return request({
    url: '/resource/booking/pending',
    method: 'get',
    params
  })
}

// 检查预订冲突
export function checkBookingConflict(params) {
  return request({
    url: '/resource/booking/check-conflict',
    method: 'get',
    params
  })
}

// 取消预订 - 修复路径，使用ResourceBookingController的路径
export function cancelBooking(id) {
  return request({
    url: `/resource/booking/cancel/${id}`,
    method: 'post'
  })
} 